#ifndef TETRIX_H
#define TETRIX_H

#define CELL_SIZE 20
#define TIMER_TIMEOUT 1000
#define TETRIX_WIDTH  20
#define TETRIX_HEIGHT 20

#include <QMainWindow>
#include <QBasicTimer>
#include <QTimer>
#include <QKeyEvent>
#include <QColor>
#include <QTime>
#include <QPoint>

#include "tetrixpiece.h"

namespace Ui {
    class Tetrix;
}

class Tetrix : public QMainWindow {
    Q_OBJECT
public:
    Tetrix(QWidget *parent = 0);
    ~Tetrix();

    static TetrixPiece createTetrixPiece();

    void showNextPiece();
protected:
    void changeEvent(QEvent *e);
    void paintEvent(QPaintEvent *);
    void timerEvent(QTimerEvent *);
    void keyPressEvent(QKeyEvent *);

    void init();
    QPoint collisionDetect();
    bool isCollision(int direction = 0);
    void handleCollision();
    void restartTimer();
    void paintPiece(int x,int y,QPainter &painter,const TetrixPiece &piece);
private:
    Ui::Tetrix *ui;
    QBasicTimer _timer;
    TetrixPiece _piece;

    int x;
    int y;

    int  _game_level;
    int _lineRemoved;
    int _board[TETRIX_HEIGHT * TETRIX_WIDTH];
    int _row_filled[TETRIX_HEIGHT];
    int _col_height[TETRIX_WIDTH];

private slots:
    void on_actionLevel_6_triggered();
    void on_actionLevel_5_triggered();
    void on_actionLevel_4_triggered();
    void on_actionLevel_3_triggered();
    void on_actionLevel_2_triggered();
    void on_actionLevel_1_triggered();
    void on_actionExit_triggered();
    void on_actionStartGame_triggered();
};

#endif // TETRIX_H
